package com.example.jnet.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class AppContext implements ApplicationContextAware {
    private static final Logger logger = LoggerFactory.getLogger(AppContext.class);

    private static ApplicationContext appContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.appContext=applicationContext;
    }

    public static <T> T  getBean(Class<T> clazz){
       return appContext.getBean(clazz);
    }

    public static ApplicationContext getAppContext(){
        return appContext;
    }
}
